package com.backsidecode.service.impl;

import com.backsidecode.mapper.CourseVariableMapper;
import com.backsidecode.pojo.entity.CourseVariable;
import com.backsidecode.pojo.entity.Courses;
import com.backsidecode.service.CourseVariableService;
import com.backsidecode.service.CoursesService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class CourseVariableServiceImpl extends ServiceImpl<CourseVariableMapper, CourseVariable>
        implements CourseVariableService {

    @Autowired
    CoursesService coursesService;

    @Override
    public List<Courses> getCourseList(Long currentId) {
        //先根据当前用户id 查询其在选课表中的选课id
        LambdaQueryWrapper<CourseVariable> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(CourseVariable::getUuid, currentId);
        lambdaQueryWrapper.select(CourseVariable::getCuid);
        List<Object> CuidList = this.listObjs(lambdaQueryWrapper);
        log.info("已选课程ID: {}", CuidList);
        //根据选课id 查询课程信息
        LambdaQueryWrapper<Courses> coursesQueryWrapper = new LambdaQueryWrapper<>();
        coursesQueryWrapper.in(Courses::getId, CuidList);

        return coursesService.list(coursesQueryWrapper);
    }
}




